<?php
header("Content-Type: text/html; charset=iso-8859-1");
class salle{
	var $fields;	
	function salle($id = "",$field = 'no'){	
		$fields = describe('salles');
		$q = "select * from salles where $field = '$id'";
		$r = ExecRequete($q);
		if(!mysql_num_rows($r)){
#			echo "Aucune salle n'a &eacute;t&eacute; trouv&eacute;e";
			foreach($fields as $field => $type) $this->$field = "";
		}
		else{
			$s = LigneSuivante($r);
			foreach($fields as $field => $type){
				$this->$field = $s->$field;
			}
		}
	}
	
	function insert(){
		$fields = describe('salles');
		$q = "replace into salles (";
		$q1 = ") values(";
		foreach($fields as $field => $type){
			$q .= $field.", ";
			$q1 .= "\"".(addslashes($this->$field))."\", ";
		}
		$q = substr($q,0,-2);
		$q1 = substr($q1,0,-2);
		$q .= $q1.")";
		if(ExecRequete($q)) return mysql_insert_id();
		else  return false;
	}
	
	function update(){
		$fields = describe('salles');
		if($this->id){
			$q = "update salles set ";
			foreach($fields as $field => $type)	{
				$q .= "$field = \"".(addslashes($this->$field))."\", ";
			}
			$q = substr($q,0,-2);
			$q .= " where id = '$this->id'";
			if(ExecRequete($q)) return true;
			else return false;
		}
		else $this->insert();
	}
	
	function delete(){
		$q = "delete from salles where id = '$this->id'";
		if(ExecRequete($q)){
			if(file_exists("salles/$this->fichier")) unlink("salles/$this->fichier");
			return true;
		}
		else return false;
	}
	
	
	
	function lien($tronquer = 1){
		$lien = ($tronquer) ? (str_ireplace("salle","",$this->nom)) : $this->nom;
		if($tronquer == 'carte') $lien = "<img src = 'images/icon_map.png' alt = 'carte' width = '32' height ='32' />";
		return  "<a href = 'javascript:show_salle($this->no)'>$lien</a>";
	}
}

?>